// toolbarButtons.cpp : Defines the entry point for the DLL application.
//

#include "stdafx.h"
#include "toolbarButtons.h"


#ifdef _MANAGED
#pragma managed(push, off)
#endif


BOOL __stdcall DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
	switch (ul_reason_for_call)
	{
	case DLL_PROCESS_ATTACH:
	case DLL_THREAD_ATTACH:
	case DLL_THREAD_DETACH:
	case DLL_PROCESS_DETACH:
		break;
	}
	return TRUE;
}

void paint(HWND pHwnd, UINT pMessage, WPARAM pWParam, LPARAM pParam)
{
	InsertButton(pHwnd, pWParam);
}

LRESULT CALLBACK NewWndProc(HWND Hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
	 //iconProc* 
     switch(Message)
     {
	 case WM_NCPAINT:
          paint(Hwnd, Message, wParam,lParam);
     }

//     return CallWindowProc((WNDPROC)iconStruct.m_oldProc, Hwnd, Message, wParam, lParam);
	 return CallWindowProc((WNDPROC)iconStruct.m_oldProc, Hwnd, WM_NCPAINT, (WPARAM)InsertButton(Hwnd), 0);
}

UNMANGLED TOOLBARBUTTONS_API int beginLoad(DllPass* str)
{
	/*MessageBoxA(HWND_DESKTOP,
        "Creation Called. Muhaha!",
        "wahoo",
        0);*/
	//InsertButton(str->m_hwnd);
	SetPropA(str->m_hwnd,"WindowProperties",str);
	iconStruct.m_oldProc = (WNDPROC)SetWindowLongA(str->m_hwnd,GWL_WNDPROC,(LONG)NewWndProc);
	return 0;
}

HRGN InsertButton(HWND hwnd, HRGN wParam)
{
	//create blank space
	HRGN whole, cutRgn;
	LPRECT rect = NULL;
	GetWindowRect(hwnd, rect); //get window rectangle
	whole = CreateRectRgnIndirect(rect);
	cutRgn = CreateRectRgn(0,0,100,100);//rect->right-200,rect->top,rect->right-100,rect->top+40);
	CombineRgn(whole,whole,cutRgn,RGN_XOR);
	HDC dc = GetWindowDC(hwnd);
	DrawFrameControl(dc,cutRgn,DFC_BUTTON,DFCS_PUSHED);
	ReleaseDC(hwnd,dc);
	DeleteObject(cutRgn);	
	return whole;
}

#ifdef _MANAGED
#pragma managed(pop)
#endif